CREATE OR REPLACE PACKAGE BODY ut_pck_compositionpath
IS
   PROCEDURE ut_setup IS
   BEGIN
     null;
   END;

   PROCEDURE ut_teardown
   IS
   BEGIN
     null;
   END;

   PROCEDURE ut_testGetPathIdString
   IS
   v_path varchar2(4000);
    v_root_node number:=pck_element.getElm_IDByBookmark('root');
   BEGIN
   		v_path := pck_compositionpath.GETPATHIDSTRING( '/[]12/[12]asdf/[23]aswer/[29]asdfer' );
		utp.utAssert.eq('idString: ', v_path ,'12,asdf,aswer,asdfer');

		v_path := pck_compositionpath.GETPATHIDSTRING( pck_compositionpath.getPath(v_root_node) );
		dbms_output.PUT_LINE( 'p:'||pck_compositionpath.getPath(v_root_node) );
		utp.utAssert.eq('idString: ', v_path ,v_root_node);
   END;

     PROCEDURE ut_testInvert(
	 v_src_path varchar2,
	 v_expected_path varchar2)
	 is
	 	 v_result_path varchar2(4000);
	 begin
	 	 v_result_path := pck_compositionpath.INVERTPATH( v_src_path );
	 	 utp.utAssert.eq('invert path: ', v_result_path,v_expected_path);
	 end;

	 PROCEDURE ut_rebuildPath_moveTest
   IS
   v_child_node number := pck_element.getElm_IDByBookmark('childnode');
   v_aut_root_node number:=pck_element.getElm_IDByBookmark('aut_root');
   v_containers_cat_id number :=pck_meta.getCat_IdByName('containers','Container','/omscube');
   v_cmp_child_node_id number;
   v_src_path varchar(4000);
   v_excpected_path varchar(4000);
   BEGIN
   		savepoint A;
   		select cmp_id into v_cmp_child_node_id from composition where
		cmp_target_elm_id =v_child_node;
   		pck_relation.moveCompositionAppend(v_cmp_child_node_id,v_aut_root_node,v_containers_cat_id,1);
		select cmp_path into v_src_path from composition where cmp_target_elm_id = v_cmp_child_node_id;

		rollback to A;
   END;

	 PROCEDURE ut_rebuildPath

	is
	v_childNode_id number:= pck_element.GETELM_IDBYBOOKMARK( 'childnode' );
	v_expected_path varchar2(4000);
	v_target_path varchar2(4000);
	begin
	select 	cmp_Path into v_expected_path from composition where cmp_target_elm_id =   v_childNode_id;
	   update composition
	   set   cmp_Path = 'test'
	   where cmp_target_elm_id = v_childNode_id;
	   	pck_compositionpath.REBUILDPATH();

		select 	cmp_Path into v_target_path from composition where cmp_target_elm_id =   v_childNode_id;
		-- ut_testInvert(v_target_path,v_expected_path );
	end;

     PROCEDURE ut_invertPath
	 is

	 begin
	 	  	ut_testInvert('/[]','[]/');
	 	  	ut_testInvert('/[]/asdf[12]/qwer','qwer/asdf[12]/[]/');
	 end;
  END;
/
